<?php

/*

Forums (forums.php)

*/

$page_title = "Slots";
$rank_check = 3;
include "header.inc.php";

if (!$bet) { $bet = 1; }
$cost_to_play = $bet * 25;

$maxPlays = 250;
if ($getInfo[premium] == 1) { $maxPlays = 500; }

if ($bet == "1") { $check1 = " SELECTED"; $percent_80 = round($cost_to_play * .8); }
if ($bet == "2") { $check2 = " SELECTED"; $percent_80 = round($cost_to_play * .72); }
if ($bet == "3") { $check3 = " SELECTED"; $percent_80 = round($cost_to_play * .64); }
if ($bet == "4") { $check4 = " SELECTED"; $percent_80 = round($cost_to_play * .56); }
if (($bet < "1") OR ($bet > "4")) { die("Please don't cheat."); }

print "$openHTML";

if ($page == "") {

print "<p>Welcome to the slots game! Hope you have fun!</p>";

}
$onehour = $timestamp - 3600;

mysql_query("DELETE FROM slots_played WHERE date_played < '$onehour' AND game = '$game'");
$getPlays = mysql_fetch_array(mysql_query("SELECT * FROM slots_played WHERE userid = '$userid' AND game = '$game'"));

if ($getPlays[total_plays] >= "$maxPlays")
{
	die("<p>You can only play $maxPlays times a hour, sorry :(</p>$closeHTML");
}

if (!$getPlays[id])
{
	mysql_query("INSERT INTO slots_played (userid,date_played,game,most_recent) VALUES ('$userid','$timestamp','$game','$timestamp')");
}

if ($getPlays[id])
{
	mysql_query("UPDATE slots_played SET total_plays=$getPlays[total_plays]+1 WHERE userid = '$userid' AND game = '$game'");
	mysql_query("UPDATE slots_played SET most_recent=$timestamp WHERE userid = '$userid' AND game = '$game'");
}

$findJackpot = fetch("SELECT * FROM slot_jackpot WHERE game = '$game'");
if (!$findJackpot[id])
{
	mysql_query("INSERT INTO slot_jackpot (game) VALUES ('$game')");
	$findJackpot = fetch("SELECT * FROM slot_jackpot WHERE game = '$game'");
}
if ($prize != "") { die("Please do not set the prize like that."); }
if ($points < "$cost_to_play") { die("You can not afford to play this game."); }

$slot = array(
"jackpot","jackpot","jackpot",
"kingofhearts","kingofhearts","kingofhearts","kingofhearts",
"queenofhearts","queenofhearts","queenofhearts","queenofhearts","queenofhearts",
"stripedgaboo","stripedgaboo","stripedgaboo","stripedgaboo","stripedgaboo","stripedgaboo","stripedgaboo",
"gaboo","gaboo","gaboo","gaboo","gaboo","gaboo","gaboo","gaboo","gaboo","gaboo","gaboo",
"loser","loser","loser","loser","loser","loser","loser","loser","loser","loser","loser","loser","loser",
);

$count_slots = count($slot) - 1;
$rand1 = rand(0,$count_slots);
$rand2 = rand(0,$count_slots);
$rand3 = rand(0,$count_slots);

if (($slot[$rand1] == "jackpot") AND (($slot[$rand2] == "jackpot") OR ($slot[$rand2] == "jackpot"))) { $prize = "500"; $reason = "2 Jackpots"; }
if (($slot[$rand2] == "jackpot") AND (($slot[$rand1] == "jackpot") OR ($slot[$rand3] == "jackpot"))) { $prize = "500"; $reason = "2 Jackpots";  }
if (($slot[$rand3] == "jackpot") AND (($slot[$rand2] == "jackpot") OR ($slot[$rand1] == "jackpot"))) { $prize = "500"; $reason = "2 Jackpots";  }
if (($slot[$rand3] == "jackpot") AND ($slot[$rand2] == "jackpot") AND ($slot[$rand1] == "jackpot")) { $prize = "$findJackpot[jackpot]"; $reason = "3 Jackpots";
mysql_query("UPDATE slot_jackpot SET jackpot=0 WHERE game = '$game'");
$findJackpot = fetch("SELECT * FROM slot_jackpot WHERE game = '$game'");
}
if (($slot[$rand1] == "kingofhearts") AND (($slot[$rand2] == "kingofhearts") OR ($slot[$rand2] == "kingofhearts"))) { $prize = "200"; $reason = "2 King of Heart Berries";  }
if (($slot[$rand2] == "kingofhearts") AND (($slot[$rand1] == "kingofhearts") OR ($slot[$rand3] == "kingofhearts"))) { $prize = "200"; $reason = "2 King of Heart Berries"; }
if (($slot[$rand3] == "kingofhearts") AND (($slot[$rand2] == "kingofhearts") OR ($slot[$rand1] == "kingofhearts"))) { $prize = "200"; $reason = "2 King of Heart Berries"; }
if (($slot[$rand3] == "kingofhearts") AND ($slot[$rand2] == "kingofhearts") AND ($slot[$rand1] == "kingofhearts")) { $prize = "1000"; $reason = "3 King of Heart Berries"; }
if (($slot[$rand1] == "queenofhearts") AND (($slot[$rand2] == "queenofhearts") OR ($slot[$rand2] == "queenofhearts"))) { $prize = "125"; $reason = "2 Queen of Heart Berries"; }
if (($slot[$rand2] == "queenofhearts") AND (($slot[$rand1] == "queenofhearts") OR ($slot[$rand3] == "queenofhearts"))) { $prize = "125"; $reason = "2 Queen of Heart Berries"; }
if (($slot[$rand3] == "queenofhearts") AND (($slot[$rand2] == "queenofhearts") OR ($slot[$rand1] == "queenofhearts"))) { $prize = "125"; $reason = "2 Queen of Heart Berries"; }
if (($slot[$rand3] == "queenofhearts") AND ($slot[$rand2] == "queenofhearts") AND ($slot[$rand1] == "queenofhearts")) { $prize = "750"; $reason = "3 Queen of Heart Berries"; }
if (($slot[$rand1] == "stripedgaboo") AND (($slot[$rand2] == "stripedgaboo") OR ($slot[$rand2] == "stripedgaboo"))) { $prize = "50"; $reason = "2 Striped Gaboo Roots"; }
if (($slot[$rand2] == "stripedgaboo") AND (($slot[$rand1] == "stripedgaboo") OR ($slot[$rand3] == "stripedgaboo"))) { $prize = "50"; $reason = "2 Striped Gaboo Roots"; }
if (($slot[$rand3] == "stripedgaboo") AND (($slot[$rand2] == "stripedgaboo") OR ($slot[$rand1] == "stripedgaboo"))) { $prize = "50"; $reason = "2 Striped Gaboo Roots"; }
if (($slot[$rand3] == "stripedgaboo") AND ($slot[$rand2] == "stripedgaboo") AND ($slot[$rand1] == "stripedgaboo")) { $prize = "450"; $reason = "3 Striped Gaboo Roots"; }
if (($slot[$rand1] == "gaboo") AND (($slot[$rand2] == "gaboo") OR ($slot[$rand2] == "gaboo"))) { $prize = "25"; $reason = "2 Gaboo Roots"; }
if (($slot[$rand2] == "gaboo") AND (($slot[$rand1] == "gaboo") OR ($slot[$rand3] == "gaboo"))) { $prize = "25"; $reason = "2 Gaboo Roots"; }
if (($slot[$rand3] == "gaboo") AND (($slot[$rand2] == "gaboo") OR ($slot[$rand1] == "gaboo"))) { $prize = "25"; $reason = "2 Gaboo Roots"; }
if (($slot[$rand3] == "gaboo") AND ($slot[$rand2] == "gaboo") AND ($slot[$rand1] == "gaboo")) { $prize = "300"; $reason = "3 Gaboo Roots"; }

if ($reason) { $reason = "<b>You got $reason!<br>"; }

if (!$prize) { $prize = "0"; }
if ($reason != "3 Jackpots")
{
	$prize = $prize * $bet;
}

print "
<center>
<p>Current Jackpot: <b>$findJackpot[jackpot]</b><br>
You added $percent_80 $pointVar to the jackpot and spin the slots!</p>

<p>
<img src=images/games/slots/$slot[$rand1].jpg border=1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<img src=images/games/slots/$images_url/$slot[$rand2].jpg border=1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<img src=images/games/slots/$images_url/$slot[$rand3].jpg border=1>
</p>

<p>$reason You won $prize $pointVar!</b></p>

<p>
<form action=slots.php?game=$game method=post>
<select name=bet>
<option value=1$check1>25 Ohms (1x)
<option value=2$check2>50 Ohms (2x)
<option value=3$check3>75 Ohms (3x)
<option value=4$check4>100 Ohms (4x)
</select>&nbsp;&nbsp;<input type=submit value=\"Pull the Lever!\">
</form>
</p>

<p><a href=games.php?game=$game>Play other Games</a></p>
</center>

";

points ("$game", "$username", "-$cost_to_play");
points ("$game", "$username", "$prize");

mysql_query("UPDATE slot_jackpot SET jackpot=$findJackpot[jackpot]+$percent_80 WHERE game = '$game'");

$timeLimit = $timestamp - 60;
$usersOn = mysql_query("SELECT userid FROM slots_played WHERE most_recent >= '$timeLimit' AND game = '$game'");
$countUsersOn = mysql_num_rows($usersOn);
while ($getUsersOn = mysql_fetch_array($usersOn))
{
	$id = $getUsersOn[userid];

	$getMember = fetch("SELECT * FROM members2 WHERE id = '$getUsersOn[userid]'");
	$members_profiles = fetch("SELECT * FROM members_profiles2 WHERE username = '$getMember[username]' AND game = '$game'");

	if ($members_profiles[gender] == 2) { $gender = "<img src=images/icons/male.gif>"; }
	if ($members_profiles[gender] == 1) { $gender = "<img src=images/icons/female.gif>"; }
	if ($members_profiles[gender] == 0) { $gender = "<img src=images/icons/undecided.gif>"; }

	if ($members_profiles[mail_settings] == 1) { $mail[$id] = "<a href=mail_send.php?game=$game&send_to=$getMember[username]><img src=images/icons/mail.gif></a>"; }
	if ($members_profiles[mail_settings] == 0) { $mail[$id] = "<a href=mail_send.php?game=$game&send_to=$getMember[username]><img src=images/icons/mail.gif></a>"; }

	$bud[$id] = "<a href=buds.php?game=$game&bud=$getMember[username]><img src=images/icons/bud.gif></a>";

	$listUsersOn .= "<tr><td valign=right><a href=$base_url/user_profile.php?game=$game&user=$getMember[username]>$getMember[display_name]</a></td>
<td width=14>$gender</td>
<td width=14>$mail[$id]</td>
<td width=14>$bud[$id]</td></tr>";
}

ECHO <<<END

<P align=center><TABLE BGCOLOR="$topAndBottomBG" CELLSPACING=1 CELLPADDING=0 WIDTH=500>
   <TR>
      <TD WIDTH=300 HEIGHT=35>
         <CENTER><FONT SIZE="+2" COLOR="$topAndBottomText"><B>--$countUsersOn Users Playing Slots--</B></FONT></CENTER>
      </TD>
   </TR>
   <TR BGCOLOR="$maincellColor">
      <TD WIDTH=250>
         <CENTER>
         <table>
         $listUsersOn
      	 </table>
      </TD>
   </TR>
</TABLE>
</P>

END;
?>